package org.example.petsystem.service.impl;


import org.example.petsystem.entity.ResultBody;
import org.example.petsystem.mapper.OrderManMapper;
import org.example.petsystem.service.OrderManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class OrderManServiceimpl implements OrderManService {
    @Autowired
    private OrderManMapper orderManMapper;
    @Override
    public int DeOrder(String code)
    {
        if(orderManMapper.DeOder(code)>0)
        {
            return 1;
        }
        return 0;
    }
    @Override
    public ResultBody displayOrder()
    {
        if(!orderManMapper.displayOrder().isEmpty())
        {
            return new ResultBody(200,"查询成功",orderManMapper.displayOrder(),orderManMapper.displayOrder().size());
        }
        else
            return new ResultBody(400,"查询失败",false);
    }
    @Override
    public ResultBody displayOrderDetailed(String phone, String code)
    {
        if(!orderManMapper.displayOrderDetailed(phone,code).isEmpty())
        {
            return new ResultBody(200,"查询成功",orderManMapper.displayOrderDetailed(phone,code),orderManMapper.displayOrderDetailed(phone,code).size());
        }
        else
            return new ResultBody(400,"查询失败",false);
    }
    @Override
    public ResultBody displayOrderSend(Map<String,Object>map)
    {
        if(!orderManMapper.displayOrderSend(map).isEmpty())
        {
            return new ResultBody(200,"查询成功",orderManMapper.displayOrderSend(map),orderManMapper.displayOrderSend(map).size());
        }
        else
            return new ResultBody(400,"查询失败",false);
    }

    @Override
    public ResultBody updateStatus(Map<String,Object>map)
    {
        if(orderManMapper.updateStatus(map)>0)
        {
            return new ResultBody(200,"修改成功",true);
        }
        else
            return new ResultBody(400,"修改失败",false);
    }
    @Override
    public ResultBody Refund(Map<String,Object>map)
    {
        if(orderManMapper.Refund(map)>0)
        {
            return new ResultBody(200,"申请退款成功",true);
        }
        else
            return new ResultBody(400,"申请退款失败",false);
    }
    @Override
    public int checkExpresscode(Map<String,Object>map)
    {
        if(orderManMapper.checkExpresscode(map)==null)
        {
            return 1;
        }
        else
            return 0;
    }
    @Override
    public ResultBody displayRefundUser(Map<String,Object>map)
    {
        if(!orderManMapper.displayRefundUser(map).isEmpty())
        {
            return new ResultBody(200,"查询成功",orderManMapper.displayRefundUser(map),orderManMapper.displayRefundUser(map).size());
        }
        else if(orderManMapper.displayRefundUser(map).isEmpty())
        {
            return new ResultBody(200,"暂时无订单",orderManMapper.displayRefundUser(map),orderManMapper.displayRefundUser(map).size());
        }
        else
            return new ResultBody(400,"查询失败",false);
    }

    @Override
    public ResultBody displayRefund()
    {
        if(!orderManMapper.displayRefund().isEmpty())
        {
            return new ResultBody(200,"显示待退款订单成功",orderManMapper.displayRefund(),orderManMapper.displayRefund().size());
        }
        else if(orderManMapper.displayRefund().isEmpty())
        {
            return new ResultBody(200,"暂时未有待退款订单",orderManMapper.displayRefund());
        }
        else
            return new ResultBody(500,"显示待退款订单失败",false);
    }

    @Override
    public ResultBody checkRefund(Map<String,Object>map) {
        if (orderManMapper.checkRefund(map) > 0) {
            String message = "已退款".equals(map.get("decision")) ? "退款成功" : "拒绝退款成功";
            return new ResultBody(200, message, true);
        } else {
            return new ResultBody(400, "处理失败", false);
        }
    }


}
